<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      .box {
        width: 100px;
        height: 100px;
        border: 1px solid;
        position: absolute;
        left: 100px;
      }
      .box::after {
        content: "";
        width: 50px;
        height: 50px;
      }
    </style>
  </head>
  <body>
    <div class="box" style="width: 500px"></div>
    <script>
      //获取非行间样式 getComputedStyle
      //   getComputedStyle(元素,伪类属性)["样式名称"]

      //获取或者设置行间样式: 元素style
      var boxEle = document.querySelector(".box");
      console.log(boxEle.style.width);
      var res = getComputedStyle(boxEle)["position"];
      console.log(res);

      //可以通过第二个参数获取伪类的属性
      /* var boxEle = document.querySelector(".box");
      var res = getComputedStyle(boxEle, "after");
      console.log(res["content"]); */

      //设置行内样式

      var boxEle = document.querySelector(".box");
      boxEle.style.background = "cyan";
    </script>
  </body>
</html>
